import { useState } from "react";
// 同页面子组件
const Son = (query: { onGetMessage: (msg: string) => void }) => {
  return (
    // 子组件调用父组件方法传入参数至父组件完成子传父
    <button onClick={() => query.onGetMessage("hello")}>点击</button>
  );
};
// 同页面父组件
const ComponentConnectSfDemo = () => {
  const [msg, setMsg] = useState("");
  // 获取参数并输出
  const getMessage = (msg: string) => {
    setMsg(msg);
  };
  return (
    <>
      {/* 父传子方法 */}
      this is father:{msg}
      <p></p>
      this is son
      <Son onGetMessage={getMessage}></Son>
    </>
  );
};

export default ComponentConnectSfDemo;
